package presentation;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import controleur.SuperControleur;

public class FenetrePrincipale extends JFrame implements ActionListener,
		WindowListener {

	private JButton btAfficher;
	private JButton btNouveau;
	private JButton btSupprimer;
	private JButton btAchat;
	private JButton btVente;
	private JButton btEnregistrer;
	private JButton btSynchroniser;
	private JButton btQuitter;

	SuperControleur sp;
	
	public FenetrePrincipale() {
		/* pour avoir le look natif. */
		try {
		    try {
				UIManager.setLookAndFeel(
				    UIManager.getSystemLookAndFeelClassName());
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (UnsupportedLookAndFeelException ex) {
		  System.out.println("Unable to load native look and feel");
		}
		sp = new SuperControleur ();
		
		setTitle("exercice Produits");
		setBounds(500, 500, 250, 200);
		JPanel panAffichage = new JPanel();
		JPanel panNouveauSupprimer = new JPanel();
		JPanel panAchatVente = new JPanel();
		/* JPanel panSauvegarderRestaurer = new JPanel(); */
		JPanel panQuitter = new JPanel();
		Container contentPane = getContentPane();
		contentPane.setLayout(new FlowLayout());
		btAfficher = new JButton("Quantités en stock");
		btNouveau = new JButton("Nouveau produit");
		btSupprimer = new JButton("Supprimer produit");
		btAchat = new JButton("Achat");
		btVente = new JButton("Vente");
		/* btEnregistrer = new JButton("Enregistrer");
		btSynchroniser = new JButton("Synchroniser"); */
		btQuitter = new JButton("Quitter");
		panAffichage.add(btAfficher);
		panNouveauSupprimer.add(btNouveau); 
		panNouveauSupprimer.add(btSupprimer);
		panAchatVente.add(btAchat); 
		panAchatVente.add(btVente);  
		/* panSauvegarderRestaurer.add(btSynchroniser);
		panSauvegarderRestaurer.add(btEnregistrer); */
		panQuitter.add(btQuitter);

		contentPane.add(panAffichage);
		contentPane.add(panNouveauSupprimer);
		contentPane.add(panAchatVente);
		/* contentPane.add(panSauvegarderRestaurer); */
		contentPane.add(panQuitter);

		btAfficher.addActionListener(this);
		btNouveau.addActionListener(this);
		btSupprimer.addActionListener(this);
		btAchat.addActionListener(this);
		btVente.addActionListener(this);
		/* btEnregistrer.addActionListener(this);
		btSynchroniser.addActionListener(this); */
		btQuitter.addActionListener(this);
		
		addWindowListener(this);
		setVisible(true);

	}

	public void actionPerformed(ActionEvent e) {   
		if (e.getSource() == btAfficher)
			new FenetreAffichage(sp.getStocks());
		if (e.getSource() == btNouveau)
			new FenetreNouveau(sp.getGestionProduit());
		if (e.getSource() == btSupprimer)
			new FenetreSuppression(sp.getGestionProduit());
		if (e.getSource() == btAchat)
			new FenetreAchat(sp.getTransactions());
		if (e.getSource() == btVente)
			new FenetreVente(sp.getTransactions());
		if (e.getSource() == btEnregistrer) 
		    ;
		if (e.getSource() == btSynchroniser)
			;

		if (e.getSource() == btQuitter) {
			System.out.println("Terminer");
			System.exit(0);
		}

	}

	public void windowClosing(WindowEvent arg0) {
		System.out.println("Terminer");
		System.exit(0);
	}

	public void windowActivated(WindowEvent arg0) {}
	public void windowClosed(WindowEvent arg0) {}
	public void windowDeactivated(WindowEvent arg0) {}
	public void windowDeiconified(WindowEvent arg0) {}
	public void windowIconified(WindowEvent arg0) {}
	public void windowOpened(WindowEvent arg0) {}

	public static void main(String[] args) {
		FenetrePrincipale f = new FenetrePrincipale();
	}

}
